//
//  ZYXPreferencesViewController.m
//  OCDataStore
//
//  Preferences 偏好设置
//

#import "ZYXPreferencesViewController.h"

@interface ZYXPreferencesViewController ()
- (IBAction)save;
- (IBAction)read;
@end

@implementation ZYXPreferencesViewController

- (IBAction)save {
    // 1.利用NSUserDefaults,就能直接访问软件的偏好设置(Library/Preferences)
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    // 2.存储数据
    [defaults setObject:@"solozyx" forKey:@"account"];
    [defaults setObject:@"123" forKey:@"pwd"];
    [defaults setInteger:24 forKey:@"age"];
    [defaults setBool:YES forKey:@"auto_login"];
    
    // 3.立刻同步
    [defaults synchronize];
}

- (IBAction)read {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    NSString *account = [defaults objectForKey:@"account"];
    BOOL autoLogin = [defaults boolForKey:@"auto_login"];
    NSLog(@"%@ -- %d", account, autoLogin);
}

// 生成的 com.solozyx.OCDataStore.plist 文件放到 Preferences 目录下供参考

// 2015-04-04 19:13:33.968 OCDataStore[25008:586291] solozyx -- 1

@end
